#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
装饰器模式
@author ：chenzf
@date ：2024/4/24 下午1:38 
"""


# def outer(func):
#     def inner():
#         print("before")
#         func()
#         print("after")
#     return inner
# def sleep():
#     import time
#     print("start sleeping ")
#     import random
#     time.sleep(random.randint(1,3))
#
#
# # fn = outer(sleep)
# # fn()
# outer(sleep)()

def outer(func):
    def inner():
        print("before")
        func()
        print("after")
    return inner
# 注解打到函数上，哪个函数就会被注入到该注解名称对应的方法入参里
@outer
def sleep():
    import time
    print("start sleeping ")
    import random
    time.sleep(random.randint(1,3))

sleep()